<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="/plugin/webman/push/push.js"> </script>
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
<body>
<table id="ws_value" lay - filter="dataTableFilter"></table>
<script>
    let ws = 1;

    // 建立连接
    var connection = new Push({
        url: 'ws://127.0.0.1:3131', // websocket地址
        app_key: '54278beb6e3e0ff2eaf265478d2c73c8',
        auth: '/plugin/webman/push/auth' // 订阅鉴权(仅限于私有频道)
    });
    // 假设用户uid为1
    var uid = 1;
    // 浏览器监听user-1频道的消息，也就是用户uid为1的用户消息
    var user_channel = connection.subscribe('world-' + uid);

    // 当user-1频道有message事件的消息时
    user_channel.on('message', function(data) {
        ws = data['content'];
        console.log(ws);
        console.log(data['content']);
    });

    layui.use(['table', 'layer'], function () {
        var table = layui.table;
        var layer = layui.layer;

        // 渲染表格
        var renderTable = function () {

            table.render( {
                elem: '#ws_value',
                cols: [[{
                    field:'world_tree', title:'World tree'
                }]],
                data: [{
                    'world_tree': ws
                }]
            })
        }
        console.log(user_channel.on('message', function (data) {
            return data['from_uid']}));
        renderTable();
        // 每隔5秒（5000毫秒）重新渲染表格
        setInterval(renderTable, 1000);
    });

</script>
</body>
</html>